<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>

<%@include file="top.jsp"%>
<%@include file="left.jsp"%>

<%	
	Connection dbcbus = db.getConnection();
	Statement stmtbus = dbcbus.createStatement();
	String sqlbus = "SELECT * FROM bustime";
	ResultSet rsbus = stmtbus.executeQuery(sqlbus);
	
	Connection dbcshot = db.getConnection();
	Statement stmtshot = dbcshot.createStatement();
	String sqlshot = "SELECT * FROM shortcut";
	ResultSet rsshot = stmtshot.executeQuery(sqlshot);
    
    Integer timeId=0;
    Integer shortcutId=0;
    Connection dbcD1 = db.getConnection();
	String sqlD1 = "SELECT timeid,shortid FROM desination";
	PreparedStatement stmtD1 = dbcD1.prepareStatement(sqlD1);
	ResultSet rsD1 = stmtD1.executeQuery();
	if(rsD1.next()){
	 timeId= rsD1.getInt("timeid");
	 shortcutId= rsD1.getInt("shortid"); 	
%> 

    <div id="content" class="align-right">
				<div id="content-ads">
					<img src="images/ads_2.png" width="800" height="90" />
				</div>
				<h2>休闲快捷</h2>
				<p>
				<form action="so_leisure_shortcut.jsp" method="post">
				  <label>时间段或场所</label>&nbsp;&nbsp;
				  <select name="timeid" class="small-input">
				  <% while(rsbus.next()){ %>
					<option 
				  <%
					if(rsbus.getInt("timeid") == timeId){
					out.print(" selected='selected'");}
				  %>
					value="<%=rsbus.getInt("timeid")%>"><%=rsbus.getString("timename")%></option>
				 <% } %>
				  </select>
				  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				  <select name="shortid" class="small-input">
				  <% while(rsshot.next()){ %>
					<option 
				  <%
					if(rsshot.getInt("shortid") == shortcutId){
					out.print(" selected='selected'");}
				  %>
					value="<%=rsshot.getInt("shortid")%>"><%=rsshot.getString("shortname")%></option>
				 <% } %>
				  </select>
				  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				
				<input class="button" type="submit" value="搜索"/>
				 </form>
				 <%}
				    rsD1.close();
				    rsshot.close();
				    rsbus.close();
				    dbcD1.close();
					dbcshot.close();
					dbcbus.close();
				%> 
			    </p>
				<div id="main-content">
					<table>
							<thead>
								<tr>
								   <th>地点图片</th>
                                   <th>地点名称</th>
								   <th>情绪描述</th>
								   <th>详细地址</th>
								   <th>联系电话</th>
								   <th>营业时间</th>
								   <th>发表时间</th>
								</tr>
								
							</thead>
						 						 
							<tbody>
		<%
			int pageNum = 1;	//当前第1页
			int pageSize = 3; //每页15条记录
			int recordCount;   //数据库的中的条数
			int pageCount;
			String strPageNum = request.getParameter("pagenum");
			if(null == strPageNum || "".equals(strPageNum)){
				
			}else{
				pageNum = Integer.parseInt(strPageNum);
			}
			
			Connection dbn = db.getConnection();
			//Statement stmt = dbc.createStatement();
			String sqln = "SELECT d.desid,d.name,d.createdate,e.emotionname,d.address,d.telephone,b.timename FROM desination AS d, emotion AS e, bustime AS b WHERE d.emotionid=e.emotionid AND d.timeid=b.timeid ";
			PreparedStatement pstmt = dbn.prepareStatement(sqln, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
			ResultSet rsn = pstmt.executeQuery();
			rsn.last();
			recordCount = rsn.getRow();
			
			if(recordCount % pageSize == 0){
				pageCount = recordCount / pageSize;
			}else{
				pageCount = recordCount / pageSize + 1;
			}
			rsn.absolute((pageNum-1)*pageSize);
			int i = 0;
			while(rsn.next() && i < pageSize){	
	   %>
								<tr class="alt-row">
									<td><img src="images/upload/item_1.png"/></td>
									<td><a title="title" href="dest_info.jsp?desid=<%=rsn.getInt("desid")%>"><%=rsn.getString("name") %></a></td>
									<td><%=rsn.getString("emotionname") %></td>
									<td><%=rsn.getString("address") %></td>
									<td><%=rsn.getString("telephone") %></td>
									<td><%=rsn.getString("timename") %></td>
									<td><%=rsn.getString("createdate") %></td>
								</tr>
			<%
				i++;
				}
                rsn.close();
				dbn.close();
			%>
							</tbody>
													
														<tfoot>
								<tr>
									<td colspan="7">
										<div class="pagination">
											<%if(pageNum != 1){ %>
											<a href="leisure_shortcut.jsp" title="首页">&laquo; 首页</a>
											<a href="leisure_shortcut.jsp?pagenum=<%= pageNum-1 %>" title="前一页">&laquo; 前一页</a>
											<%} %>
											当前<%= pageNum%>页/共<%= pageCount%>页
											<%if(pageNum != pageCount){ %>
											<a href="leisure_shortcut.jsp?pagenum=<%= pageNum+1 %>" title="后一页">后一页 &raquo;</a>
											<a href="leisure_shortcut.jsp?pagenum=<%= pageCount %>" title="末页">末页 &raquo;</a>
											<%} %>
										</div> <!-- End .pagination -->
										<div class="clear"></div>
									</td>
								</tr>
							</tfoot>
						</table>
					</div>
			</div>

<!-- 特殊 选中样式 -->
<script type="text/javascript">
	
	$(document).ready(function(){
		
		/*选中，如下*/
		$('#li-shortcut').addClass('on');
		
	});
</script>

<%@include file="bottom.jsp"%>
